﻿using AiQiuQuan.Sport.Model.Enums;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;

namespace AiQiuQuan.Sport.Model.Models
{
    /// <summary>
    /// 课程相关状态、标记修改
    /// </summary>
    public class CourseFlagUpdateDto : IValidatableObject
    {
        /// <summary>
        /// 课程ID
        /// </summary>
        [Required]
        public Guid CourseId { get; set; }

        /// <summary>
        /// 课程状态
        /// </summary>
        public CourseStateEnum? CourseState { get; set; }

        /// <summary>
        /// 是否展示
        /// </summary>
        public bool? IsShow { get; set; }

        /// <summary>
        /// 是否推荐
        /// </summary>
        public bool? IsRecommend { get; set; }

        /// <summary>
        /// 是否平台
        /// </summary>
        [JsonIgnore]
        public bool IsPlatform { get; set; }

        /// <summary>
        /// validate
        /// </summary>
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (!CourseState.HasValue && !IsShow.HasValue && !IsRecommend.HasValue)
            {
                yield return new ValidationResult("至少更新一个字段");
                yield break;
            }

            if (CourseState != CourseStateEnum.Processing && CourseState != CourseStateEnum.Stoped && CourseState != CourseStateEnum.Finished)
            {
                yield return new ValidationResult("课程状态不正确");
                yield break;
            }
        }
    }
}
